extends "../cTDM/cTDM.gd"
func _info():
	pass

func _connect():
	._connect()

var norcnt:int = 0
var tlv = 0
var nlv = 0
var spw1 = 15
var spw2 = 10
var spw3 = 3
var soulcnt:int = 0

func _extInit():
	._extInit()
	#chaName = "圣剑客·Lv[0]"
	lv = 4
	attCoe.atkRan = 3
	attCoe.atk = 25 / 8.5 * 2 / 4
	attCoe.maxHp = 480 / 112.5 / 4
	addSkillTxt("奥术飞弹·魂：奥术飞弹附加魂属性，33%概率使敌人附加1层<眩晕>")
	addSkillTxt("灵魂痛击：收集敌方死者灵魂[全局有效]；攻击有10%概率对另外4个随机敌方造成相同伤害")
	addSkillTxt("灵魂痛击·改：[灵魂痛击]概率改为<15+技能等级>%[color=#666666][未解锁][/color]")
	addSkillTxt("灵魂风暴：普攻[击中时]有10%消耗一半灵魂造成2次<灵魂数 *（10+技能等级）>点真实伤害[color=#666666][未解锁][/color]")
	addSkillTxt("灵魂强化：灵魂风暴攻击次数改为<3+技能等级/3>[color=#666666][未解锁][/color]")
	addSkillTxt("[color=red]Tips:杀人会获得经验，战斗结束后会计算经验并升级;升级获得的属性和解锁的技能及等级全局有效")
	nlv = 0
	lvup()
	if skill3unlock:
		skillunlock(3)
	if skill2unlock:
		skillunlock(2)
	if skill1unlock:
		skillunlock(1)

func _onCharaDel(cha):
	._onCharaDel(cha)
	if cha.team != self.team && cha.get("ischange") == false:
		soulcnt += 1

func _onBattleStart():
	._onBattleStart()
	if sys.test:
		lvup()
		if !skill3unlock:
			#print("unlock3")
			skillunlock(3)

func _onAtkChara(atkinfo):
	if atkinfo.atkType != Chara.AtkType.EFF && !atkinfo.isMiss:
		var txt = "灵魂痛击"
		var pw = 10
		if skill1unlock:
			txt += "·改"
			skill1up()
			pw = spw1
		if sys.rndPer(pw):
			var chas = atkinfo.hitCha.getAllChas(2)
			if chas.size() > 1:
				cst(txt,"000000",position)
				chas.remove(chas.find(atkinfo.hitCha))
				var nchas = rndChas(chas,4)
				if nchas:
					if nchas.has_method("size"):
						for i in nchas:
							hurtChara(i,atkinfo.hurtVal,atkinfo.hurtType,atkinfo.atkType)
					else:
						hurtChara(nchas,atkinfo.hurtVal,atkinfo.hurtType,atkinfo.atkType)

	if atkinfo.atkType == Chara.AtkType.NORMAL && !atkinfo.isMiss && atkinfo.hitCha != self && atkinfo.atkCha == self:
		if skill2unlock:
			if sys.rndPer(10):
				if soulcnt:
					cst("灵魂风暴","000000",position)
					skill2up()
					var n = 2
					if skill3unlock:
						skill3up()
						n = spw3
					var dmg = soulcnt * spw2
					soulcnt *=0.5
					for i in range(n):
						hurtChara(atkinfo.hitCha,dmg,Chara.HurtType.REAL,Chara.AtkType.SKILL)
	._onAtkChara(atkinfo)

#战后计算经验
func _onBattleEnd():
	._onBattleEnd()
	yield(reTimer(0.01),"timeout")
	lvup()
	upAtt()
#升级改名改等级
func lvup():

	#if chaName.find("Lv[") == -1:
	#	nlv = 0
	#else:
	#	nlv = int(chaName.right(chaName.find("[")).left(2))
		
	if killNum >= 2:
		tlv = 1
	var e = 2
	var k = 3
	while(killNum >= e + k):
		tlv += 1
		e = e + k
		k += 1
	if sys.test:tlv = nlv + 1
	tlv = min(18,tlv)
	if tlv > nlv:
		upattadd(tlv,nlv)
		nlv = tlv
	chaName = "灵魂术士·Lv[" + str(nlv) + "]"
#升级修改属性
func upattadd(tlv,nlv):
	attAdd.atk += (tlv - nlv) * 6
	attAdd.maxHp += (tlv - nlv) * 68
	attAdd.spd += (tlv - nlv) * 0.025
	attAdd.cd += (tlv - nlv) * 0.02
	healCha(self,(tlv - nlv) * 10)
#修改技能1系数
func skill1up():
	spw1 = 15 + skill1lv
#修改技能2系数
func skill2up():
	spw2 = 10 + skill2lv
#修改技能3系数
func skill3up():
	spw3 = 3 + int(skill3lv / 3)